import Qt 4.7
import QtQuick 1.0
//import QtMultimediaKit 1.1

import "script.js" as Logic

Rectangle {
    id:container
    width: 640
    height: 270

    property bool tick: false
    property bool isMenuOpen: false
    property bool colorButton: true

    function showMenu()
    {
        menuitem1.x = 440
        menuitem1.y = 10
        menuitem2.x = 400
        menuitem2.y = 100
        menuitem3.x = 440
        menuitem3.y = 190
        isMenuOpen = !isMenuOpen
    }

    function hideMenu()
    {
        menuitem1.x = 900
        menuitem1.y = 130
        menuitem2.x = 900
        menuitem2.y = 130
        menuitem3.x = 900
        menuitem3.y = 130
        isMenuOpen = !isMenuOpen
    }

//    Audio {
//             id: playMusic
//             source: "d:\\move.wav"
//             volume: 1.0
//         }

    // Game Field Mouse Area
    MouseArea {
        id: mouse_area1
        anchors.fill: parent
        x: 78
        y: -2
        width: 310
        height: 300
        anchors.topMargin: -2
        anchors.leftMargin: 78
        z: 2
        anchors.rightMargin: 252
        anchors.bottomMargin: 2
        onClicked:
        {
            Logic.step(mouse.x, mouse.y);
            //playMusic.play();
        }
    }

    // Menu show/hide button
    Image {
        id: image2
        x: 0
        y: -5
        width: 640
        height: 270
        source: "Back.png"

        Image {
            id: image1
            x: 495
            y: 90
            source: "st1.png"

            SequentialAnimation {
                     running: true
                     PropertyAnimation { target: image1; property: "source"; to: "st2.png"; duration: 200 }
                     PropertyAnimation { target: image1; property: "source"; to: "st3.png"; duration: 200 }
                     PropertyAnimation { target: image1; property: "source"; to: "st4.png"; duration: 200 }
                     PropertyAnimation { target: image1; property: "source"; to: "st3.png"; duration: 200 }
                     PropertyAnimation { target: image1; property: "source"; to: "st2.png"; duration: 200 }
                     PropertyAnimation { target: image1; property: "source"; to: "st1.png"; duration: 200 }
                     loops:  Animation.Infinite
                 }
        }

        MouseArea {
            id: mouse_area2
            x: 500
            y: 93
            width: 133
            height: 80
            z: 5
            onClicked:
            {
                if (!isMenuOpen)
                {
                    showMenu()
                } else
                {
                    hideMenu()
                }
            }
        }
    }


        MenuItem
        {
            id: menuitem1
            x: 900
            y: 150
            onClicked:
            {
                Logic.newGame(false)
                hideMenu()
            }
            z: 5
        }

        MenuItem
        {
            id: menuitem2
            x: 900
            y: 150
            srcPic: "pvi.png"
            onClicked: { Logic.newGame(true); hideMenu(); }
            z: 5
        }

        MenuItem
        {
            id: menuitem3
            x: 900
            y: 150
            srcPic: "exit.png"
            onClicked: { Qt.quit() }
            z: 5
        }
}
